package com.example.springboot.Controller;

import com.example.springboot.common.Result;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 功能:提供接口返回数据
 * 作者：jian
 * 日期：2024/3/13 13:13
 */
@RestController
public class WebTestController {
    /**
     * @RequestMapping(method = RequestMethod.GET)
     * @RequestMapping(method = RequestMethod.POST)
     * @RequestMapping(method = RequestMethod.PUT)
     * @RequestMapping(method = RequestMGetod.DELETE)
     */

    //默认是访问'/' 默认是get请求
    @GetMapping("/hello") // //http://localhost:8080/web/hello
    public Result hello(String name) {
        return Result.success(name);
    }

    //post新增数据
    @PostMapping("/post")       //http://localhost:8080/web/post?name=戬哥哥&age=23
    public Result post(@RequestBody Obj1 obj) {  //@RequestBody可以把前端提交的json（直接收json不然报错400接口错误）转换为一个java对象
        return Result.success(obj);
    }

    //put更改数据
    @PutMapping("/put")
    public Result put(@RequestBody Obj1 obj) {
        return Result.success(obj);
    }

    //删除数据，也可以穿json参数@RequestBody
    @DeleteMapping("/delete/{id}")  //http://localhost:8080/web/delete/1
    public Result delete(@PathVariable Integer id) { //路径参数
        return Result.success(id);
    }

    @DeleteMapping("/delete1")  //http://localhost:8080/web/delete/1
    public Result delete(@RequestBody List<Integer> ids) { //路径参数
        return Result.success(ids);
    }

}   